package com.example.lenovo.dynamicproxy_lxy;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.example.lenovo.dynamicproxy_lxy.proxy.DynamicProxy;
import com.example.lenovo.dynamicproxy_lxy.proxy.RealSubject;
import com.orhanobut.logger.Logger;

import java.lang.reflect.Proxy;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {


    private Button mStaticProxy;
    private String LogStr = "MainActivity";
    private Button mBtDynamicProxy;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Logger.init(LogStr);
        setContentView(R.layout.activity_main);
        initView();
        initListener();
    }

    private void initListener() {
        mBtDynamicProxy.setOnClickListener(this);
    }

    private void initView() {
        mBtDynamicProxy = (Button) findViewById(R.id.btDynamicProxy);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btDynamicProxy:
                RealSubject real = new RealSubject();
                Subject proxySubject = (Subject) Proxy.newProxyInstance(Subject.class.getClassLoader(),new Class[]{Subject.class}, new DynamicProxy(real));
//                proxySubject.dealTask("李阳");
                proxySubject.dealTaskCompletion();
                break;

        }
    }
}
